package com.ease.model.criterion;

import java.util.List;

import com.ease.common.vo.Entry;

/**
 * 
 * @author nathanleewei
 * 
 */
public class BetweenExpression extends CriterionSupport implements Criterion {

	/**
	 *
	 */
	private static final long serialVersionUID = 3776505282082530871L;

	private String propertyName;
	private Object lo;
	private Object hi;
	private String op;

	public String getOp() {
		return op;
	}

	public void setOp(String op) {
		this.op = op;
	}

	/* for flex */
	public BetweenExpression() {

	}

	public String getPropertyName() {
		return propertyName;
	}

	public void setPropertyName(String propertyName) {
		this.propertyName = propertyName;
	}

	public Object getLo() {
		return lo;
	}

	public void setLo(Object lo) {
		this.lo = lo;
	}

	public Object getHi() {
		return hi;
	}

	public void setHi(Object hi) {
		this.hi = hi;
	}

	protected BetweenExpression(String propertyName, Object lo, Object hi) {
		this.propertyName = propertyName;
		this.lo = lo;
		this.hi = hi;
	}

	public String toString() {
		return propertyName + " between " + lo + " and " + hi;
	}

	public String toSqlString(QueryCriteria queryCriteria) {
		StringBuffer fragment = new StringBuffer();
		fragment.append(queryCriteria.getColumnNameByPropertyName(propertyName, lo)).append(" between ? and ?");
		return fragment.toString();
	}

	public List<Entry<String, Object>> getNamedValue(QueryCriteria queryCriteria) {
		List<Entry<String, Object>> namedValue = this.safeNamedValue(null);
		namedValue.add(new Entry<String, Object>(propertyName + "_lo", lo));
		namedValue.add(new Entry<String, Object>(propertyName + "_hi", hi));
		return namedValue;
	}

}
